package cn.xiaou.view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import cn.xiaou.domain.User;
import cn.xiaou.domain.UserReal;
import cn.xiaou.draw.MyJButtom;
import cn.xiaou.service.UserService;
import cn.xiaou.service.impl.UserServiceImpl;
import cn.xiaou.utils.FontUtils;
import cn.xiaou.utils.ImageManagerUtils;
public class Information extends JFrame {
	private static final long serialVersionUID = 1L;
	private JPanel panel=new JPanel();
	private JLabel nickname=new JLabel("昵称：");
	private JLabel sex=new JLabel("性别：");
	private JLabel money=new JLabel("当前资金：");
	private JLabel email=new JLabel("绑定邮箱：");
	private JLabel name=new JLabel("真实姓名：");
	private JLabel nickname2=new JLabel("");
	private JLabel sex2=new JLabel("");
	private JLabel money2=new JLabel("");
	private JLabel email2=new JLabel("");
	private JLabel name2=new JLabel("");
	private JLabel loginBg;
	private JButton Come;
	private UserService userService = new UserServiceImpl();
//	Container ct;
//	BackgroundPanel bgp;
	
	public Information(User user,JFrame MainFrame) {
		this.add(panel);
		//显示窗体
		setSize(500,600);
		setLocationRelativeTo(null);
		setUndecorated(true);
		setAlwaysOnTop(true);
		setIconImage(getToolkit().getImage(ImageManagerUtils.icoUrl));
		setLocationRelativeTo(null);//窗体居中
		setResizable(false);//窗体大小不可以调
		/*Toolkit tk = Toolkit.getDefaultToolkit();
		Image image = tk.createImage(System.getProperty("user.dir")+"\\img\\ico.png"); 
	    setIconImage(image);*/
	    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    
		setLayout(new BorderLayout());
		loginBg = new JLabel();// 背景标签
		loginBg.setVerticalAlignment(SwingConstants.TOP);
		loginBg.setHorizontalAlignment(SwingConstants.CENTER);
		add(loginBg,BorderLayout.NORTH);
		
		ImageIcon background = new ImageIcon(ImageManagerUtils.InformationBg);
		JLabel bg = new JLabel(background);
		bg.setBounds(0, 0, background.getIconWidth(),background.getIconHeight());
		JPanel panel = (JPanel) getContentPane();  
		 //设置透明
		panel.setOpaque(false);
		 //将背景图的label置于窗体的底层
		getLayeredPane().add(bg, new Integer(Integer.MIN_VALUE));  
		setLocationRelativeTo(null);
		setLayout(null);
		panel.setLayout(null);
		setUndecorated(true);
	    setBackground(new Color(0,0,0,0));
		User Reuser = userService.loginUser(user.getUsername(), user.getPassword());
	    nickname.setBounds(30,40,150,50);
	    nickname.setFont(FontUtils.font2);
		panel.add(nickname);
		nickname2.setBounds(80,51,150, 30);
		nickname2.setFont(FontUtils.font2);
		panel.add(nickname2);
		nickname2.setText(Reuser.getUsername());
			
		sex.setBounds(300,40,150,50);
		sex.setFont(FontUtils.font2);
		panel.add(sex);
		sex2.setBounds(350,51,40, 30);
		sex2.setFont(FontUtils.font2);
		panel.add(sex2);
		if("0".equals(Reuser.getGender())) {
			sex2.setText("女");
		}else {
			sex2.setText("男");
		}
			
		email.setBounds(30,140,150,50);
		email.setFont(FontUtils.font2);
		panel.add(email);
		email2.setBounds(115,150,250, 30);
		panel.add(email2);
		email2.setFont(FontUtils.font2);
		email2.setText(Reuser.getEmail());
			
		money.setBounds(30,240,150,50);
		money.setFont(FontUtils.font2);
		panel.add(money);
		money2.setBounds(115,250,200, 30);
		money2.setFont(FontUtils.font2);
		panel.add(money2);
		money2.setText("￥ "+Reuser.getMoney().toString());
			
		name.setBounds(30,340,150,50);
		name.setFont(FontUtils.font2);
		panel.add(name);
		name2.setBounds(115,350,150, 30);
		panel.add(name2);
		UserReal userReal = userService.checkRealnameExist(Reuser);
		name2.setFont(FontUtils.font2);
		if(userReal !=null) {
			name2.setText(userReal.getRealname());
		}else {
			name2.setText("未实名");
		}
		
		
		/*Close=new JButton("关闭");
	    Close.setFont(new java.awt.Font("微软雅黑",1,18));
	    panel.add(Close);
	    Close.setBounds(360, 500, 90, 40);*/
	    
		Come=new MyJButtom(ImageManagerUtils.logoutBg);
		Come.setFont(FontUtils.font2);
	    panel.add(Come);
	    Come.setBounds(360, 500, 60, 60);
	    Come.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				MainFrame.setEnabled(true);
				dispose();
			}
		});
	    
	    setVisible(true);
		
	}	
//	public static void main(String[] args) {
//		 new Information(new User(),null);
//	}
}

